﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessHanler;

namespace BusinessHandler
{
    public class CategoryController : NewsDataClassesDataContext
    {
        private static CategoryController instance;
        public static CategoryController Instance
        {
            get
            {
                if (instance==null)
                {
                    instance=new CategoryController();
                }
                return instance;
            }
            set
            {
                instance=value;
            }
        }
        public List<Category> GetCategoryforInsertNews()
        {
            NewsDataClassesDataContext context=new NewsDataClassesDataContext();
            var list=(from tmp in context.Categories
                      where tmp.CategoryParentID==null&&tmp.IsAddNews==true
                      select tmp).ToList();
            if (list!=null)
            {
                return (List<Category>)list;
            }
            return null;
        }
        public List<Category> GetAllChildCat()
        {
            NewsDataClassesDataContext context=new NewsDataClassesDataContext();
            var list=(from tmp in context.Categories
                      where tmp.CategoryParentID!=null&&tmp.IsAddNews==true
                      select tmp).ToList();
            if (list!=null)
            {
                return (List<Category>)list;
            }
            return null;
        }
        public List<Category> GetAllCat()
        {
            NewsDataClassesDataContext context=new NewsDataClassesDataContext();
            var list=(from tmp in context.Categories
                      select tmp).ToList();
            if (list!=null)
            {
                return (List<Category>)list;
            }
            return null;
        }
    }
}